package org.d2_recursion.d2_recursion;

/**
 * 啤酒问题
 */
public class RecursionText6 {
    public static int totalNumber;//总酒数
    public static int lastBottleNumber;
    public static int lastCoverNumber;
   public static void main(String[] args) {
        //啤酒两元一瓶，四个盖子换一瓶，2个空瓶换一瓶。请问10元可以喝多少瓶
        //将他们都转化成钱的问题
       buy (10);
       System.out.println("总数："+ totalNumber);
       System.out.println("总瓶子数："+ lastBottleNumber);
       System.out.println("总瓶盖数："+ lastCoverNumber);

  }
  public static void buy (int money){
       //1.先买了再说，
       int buyNumber = money / 2;
       totalNumber += buyNumber;
       //2.把瓶子和盖子换算成钱继续买
      //计算本轮的瓶子和盖子数量
      int allBottleNumber = buyNumber + lastBottleNumber;
      int allCoverNumber =  buyNumber + lastCoverNumber;
      int allmoney = 0;

      if (allBottleNumber >= 2){
          allmoney += (allBottleNumber/2) * 2;
      }
      lastBottleNumber = allBottleNumber % 2;
      if(allCoverNumber >= 4){
          allmoney += (allCoverNumber / 4) * 2;
      }
        lastCoverNumber =allCoverNumber % 4;
      if(allmoney >= 2){
          buy(allmoney);
      }
  }
}
